package com.venta.autopartes.vehicle.search;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.venta.autopartes.car.ModelVehicle;
import com.venta.autopartes.car.SubModelVehicle;
import com.venta.autopartes.car.YearVehicle;
import com.venta.autopartes.dao.VehicleDAO;

public class VehicleCharacteristicsRetriver extends ActionSupport {

	private String makeVehicle;
	private String modelVehicle;
	private String yearVehicle;
	private String versionVehicle;
	private String subModelVehicle;
	private String versionSubModelVehicle;
	private Object jsonModel;

	public String execute() {
		VehicleDAO vehicleDAO= new VehicleDAO();
		List<Object> characteristicsVehicleList = null;
		
		if(makeVehicle!=null){
			characteristicsVehicleList=vehicleDAO.getModelVehicleList(makeVehicle);
		}else if(modelVehicle!=null){
			List<Object> yearVehicleList = vehicleDAO.getYearByModelVehicleList(modelVehicle);
			characteristicsVehicleList=new ArrayList<Object>();
			for(Object obj:yearVehicleList){
				YearVehicle yearVehicle=(YearVehicle)obj;
				
				ModelVehicle modelVehicle=new ModelVehicle(yearVehicle.getYearId(),yearVehicle.getYear(),yearVehicle.getModelId());
				
				characteristicsVehicleList.add(modelVehicle);
			}
			
		}else if(yearVehicle!=null){
			List<Object> yearVehicleList = vehicleDAO.getSubmodelByYearVehicleList(yearVehicle);
			characteristicsVehicleList=new ArrayList<Object>();
			for(Object obj:yearVehicleList){
				SubModelVehicle subModelVehicle=(SubModelVehicle)obj;
				
				ModelVehicle modelVehicle=new ModelVehicle(subModelVehicle.getSubModelVehicleId(),subModelVehicle.getSubModelVehicle());
				
				characteristicsVehicleList.add(modelVehicle);
			}
		}

		setJsonModel(characteristicsVehicleList);
		return SUCCESS;
	}

	public String getMakeVehicle() {
		return makeVehicle;
	}

	public void setMakeVehicle(String makeVehicle) {
		this.makeVehicle = makeVehicle;
	}

	public Object getJsonModel() {
		return jsonModel;
	}

	public void setJsonModel(Object jsonModel) {
		this.jsonModel = jsonModel;
	}

	public String getModelVehicle() {
		return modelVehicle;
	}

	public void setModelVehicle(String modelVehicle) {
		this.modelVehicle = modelVehicle;
	}

	public String getVersionVehicle() {
		return versionVehicle;
	}

	public void setVersionVehicle(String versionVehicle) {
		this.versionVehicle = versionVehicle;
	}

	public String getSubModelVehicle() {
		return subModelVehicle;
	}

	public void setSubModelVehicle(String subModelVehicle) {
		this.subModelVehicle = subModelVehicle;
	}

	public String getVersionSubModelVehicle() {
		return versionSubModelVehicle;
	}

	public void setVersionSubModelVehicle(String versionSubModelVehicle) {
		this.versionSubModelVehicle = versionSubModelVehicle;
	}

	public String getYearVehicle() {
		return yearVehicle;
	}

	public void setYearVehicle(String yearVehicle) {
		this.yearVehicle = yearVehicle;
	}

	
	
}
